﻿using FBProject.BusinessLogic.MSProjectProxies;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.Office.Interop.MSProject;
using FBProject.BusinessLogic;

namespace FBProjectTest
{
    
    
    /// <summary>
    ///This is a test class for MSTaskProxyTest and is intended
    ///to contain all MSTaskProxyTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MSTaskProxyTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Completed
        ///</summary>
        [TestMethod()]
        public void CompletedTest()
        {
            var application = new MockObjects.MSProject.ApplicationMock();
            var tasks = new MockObjects.MSProject.TasksMock();
            var project = new MockObjects.MSProject.ProjectMock(application, tasks);
            var msProjectProxy = new MSProjectProxy(application);
            var task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11111",
                Name = "Task 1"
            });
            task.Work = 20;
            task.RemainingWork = 20;

            task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11112",
                Name = "Task 2"
            });
            task.Work = 20;
            task.RemainingWork = 0;

            Assert.AreEqual<bool>(false, msProjectProxy.Tasks[1].Completed);
            Assert.AreEqual<bool>(true, msProjectProxy.Tasks[2].Completed);
        }

        /// <summary>
        ///A test for IsExternalTask
        ///</summary>
        [TestMethod()]
        public void IsExternalTaskTest()
        {
            var application = new MockObjects.MSProject.ApplicationMock();
            var tasks = new MockObjects.MSProject.TasksMock();
            var project = new MockObjects.MSProject.ProjectMock(application, tasks);
            var msProjectProxy = new MSProjectProxy(application);
            var task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11111",
                Name = "Task 1"
            });

            task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11112",
                Name = "Task 2"
            });
            task.TaskNumber = string.Empty;

            Assert.AreEqual<bool>(true, msProjectProxy.Tasks[1].IsExternalTask);
            Assert.AreEqual<bool>(false, msProjectProxy.Tasks[2].IsExternalTask);
        }

        /// <summary>
        ///A test for TaskDescription
        ///</summary>
        [TestMethod()]
        public void FBCaseDescriptionTest()
        {
            var application = new MockObjects.MSProject.ApplicationMock();
            var tasks = new MockObjects.MSProject.TasksMock();
            var project = new MockObjects.MSProject.ProjectMock(application, tasks);
            var msProjectProxy = new MSProjectProxy(application);
            var task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11111",
                Name = "Task 1"
            });

            task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11112",
                Name = "Task 2"
            });
            task.TaskNumber = string.Empty;

            Assert.AreEqual<string>("FB11111 Task 1", msProjectProxy.Tasks[1].FBCaseDescription);
            Assert.AreEqual<string>("Task 2", msProjectProxy.Tasks[2].FBCaseDescription);
        }

        /// <summary>
        ///A test for TaskHyperlink
        ///</summary>
        [TestMethod()]
        public void TaskHyperlinkTest()
        {
            var application = new MockObjects.MSProject.ApplicationMock();
            var tasks = new MockObjects.MSProject.TasksMock();
            var project = new MockObjects.MSProject.ProjectMock(application, tasks);
            var msProjectProxy = new MSProjectProxy(application);
            var task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11111",
                Name = "Task 1"
            });

            task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11112",
                Name = "Task 2"
            });
            task.TaskNumber = string.Empty;

            Assert.AreEqual<string>(string.Empty, msProjectProxy.Tasks[1].TaskHyperlink);
            Assert.AreEqual<string>(string.Empty, msProjectProxy.Tasks[2].TaskHyperlink);

            msProjectProxy.FBUrl = "http://sample.fogbugz.com";
            Assert.AreEqual<string>("http://sample.fogbugz.com/default.asp?11111", msProjectProxy.Tasks[1].TaskHyperlink);
            Assert.AreEqual<string>(string.Empty, msProjectProxy.Tasks[2].TaskHyperlink);

            msProjectProxy.FBUrl = "http://sample.fogbugz.com/";
            Assert.AreEqual<string>("http://sample.fogbugz.com/default.asp?11111", msProjectProxy.Tasks[1].TaskHyperlink);
            Assert.AreEqual<string>(string.Empty, msProjectProxy.Tasks[2].TaskHyperlink);

            msProjectProxy.FBCaseUrlFormat = "{0}index.php?id={1}";
            Assert.AreEqual<string>("http://sample.fogbugz.com/index.php?id=11111", msProjectProxy.Tasks[1].TaskHyperlink);
            Assert.AreEqual<string>(string.Empty, msProjectProxy.Tasks[2].TaskHyperlink);
        }

        /// <summary>
        ///A test for TaskNumberFormatted
        ///</summary>
        [TestMethod()]
        public void TaskNumberFormattedTest()
        {
            var application = new MockObjects.MSProject.ApplicationMock();
            var tasks = new MockObjects.MSProject.TasksMock();
            var project = new MockObjects.MSProject.ProjectMock(application, tasks);
            var msProjectProxy = new MSProjectProxy(application);
            var task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11111",
                Name = "Task 1"
            });

            task = msProjectProxy.AddTask(new ExternalTask()
            {
                TaskNumber = "11112",
                Name = "Task 2"
            });
            task.TaskNumber = string.Empty;

            Assert.AreEqual<string>("FB11111", msProjectProxy.Tasks[1].TaskNumberFormatted);
            Assert.AreEqual<string>(string.Empty, msProjectProxy.Tasks[2].TaskNumberFormatted);

            msProjectProxy.FBCaseNumberFormat = "FB#{0}";
            Assert.AreEqual<string>("FB#11111", msProjectProxy.Tasks[1].TaskNumberFormatted);
            Assert.AreEqual<string>(string.Empty, msProjectProxy.Tasks[2].TaskNumberFormatted);
        }
    }
}
